package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyHatchExtraRewardsConfig;
import com.sc.nft.entity.EcologyHatchExtraRewardsMethodConf;
import com.sc.nft.entity.EcologyHatchMethodCollectionConf;
import com.sc.nft.entity.EcologyHatchUsePropsExchange;
import com.sc.nft.enums.EcologyRewardsType;
import com.sc.nft.mapper.EcologyHatchExtraRewardsConfigMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * @author 朱梦晨
 * @Description:
 * @date 2024-09-24
 */
@Slf4j
@Repository
public class EcologyHatchExtraRewardsConfigDao extends ServiceImpl<EcologyHatchExtraRewardsConfigMapper, EcologyHatchExtraRewardsConfig> {



    /**
     * 根据奖励配置id
     *
     * @param extraRewardsId
     * @return
     */
    public List<EcologyHatchExtraRewardsConfig> findEcologyHatchExtraRewardsConfigListByExtraRewardsId(Long extraRewardsId,Long methodId) {
        LambdaQueryWrapper<EcologyHatchExtraRewardsConfig> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(EcologyHatchExtraRewardsConfig::getExtraRewardsId,extraRewardsId);
        if (Objects.nonNull(methodId)){
            queryWrapper.eq(EcologyHatchExtraRewardsConfig::getMethodId, methodId);
        }
        queryWrapper.eq(EcologyHatchExtraRewardsConfig::getIsDelete,Boolean.FALSE);
        return baseMapper.selectList(queryWrapper);
    }


    /**
     * 获取熔炼关联表
     *
     * @param ecologyHatchId
     * @param extraRewardsId
     * @return
     */
    public EcologyHatchExtraRewardsConfig getOneByEcologyHatchId(Long ecologyHatchId, Long extraRewardsId) {
        LambdaQueryWrapper<EcologyHatchExtraRewardsConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchExtraRewardsConfig::getEcologyHatchId, ecologyHatchId);
        wrapper.eq(EcologyHatchExtraRewardsConfig::getExtraRewardsId, extraRewardsId);
        wrapper.eq(EcologyHatchExtraRewardsConfig::getIsDelete, Boolean.FALSE);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }


    /**
     * 修改
     * @param id
     * @param deliveryCycle
     * @param linkId
     * @param linkCount
     * @param linkImage
     * @param linkName
     * @param status
     * @return
     */
    public boolean updateEcologyHatchExtraRewardsConfig(Long id, Integer deliveryCycle, Long linkId, BigDecimal linkCount,
                                                        String linkImage, String linkName, EcologyRewardsType rewardsType) {
        LambdaUpdateWrapper<EcologyHatchExtraRewardsConfig> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchExtraRewardsConfig::getId, id);
        wrapper.set(EcologyHatchExtraRewardsConfig::getDeliveryCycle, deliveryCycle);
        wrapper.set(EcologyHatchExtraRewardsConfig::getLinkId, linkId);
        wrapper.set(EcologyHatchExtraRewardsConfig::getLinkCount, linkCount);
        wrapper.set(EcologyHatchExtraRewardsConfig::getLinkImage, linkImage);
        wrapper.set(EcologyHatchExtraRewardsConfig::getLinkName, linkName);
        wrapper.set(EcologyHatchExtraRewardsConfig::getRewardsType, rewardsType);
        return update(new EcologyHatchExtraRewardsConfig(), wrapper);
    }

    public boolean updateMethodId(Long extraRewardsId, Long methodId) {
        LambdaUpdateWrapper<EcologyHatchExtraRewardsConfig> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchExtraRewardsConfig::getExtraRewardsId, extraRewardsId);
        wrapper.set(EcologyHatchExtraRewardsConfig::getMethodId, methodId);
        return update(new EcologyHatchExtraRewardsConfig(), wrapper);
    }



    /**
     * 根据熔炼兑换配置id和熔炼配置id获取列表
     *
     * @param extraRewardsId
     * @return
     */
    public List<EcologyHatchExtraRewardsConfig> findAdminListByMethodId(Long methodId) {
        LambdaQueryWrapper<EcologyHatchExtraRewardsConfig> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(EcologyHatchExtraRewardsConfig::getMethodId, methodId);
        return baseMapper.selectList(queryWrapper);
    }



    public boolean deleteEcologyHatchExtraRewardsConfigById(Long id) {
        return removeById(id);
    }

    public List<EcologyHatchExtraRewardsConfig> listByExtraRewardsId(Long extraRewardsId,Long ecologyHatchId) {
        LambdaQueryWrapper<EcologyHatchExtraRewardsConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EcologyHatchExtraRewardsConfig::getExtraRewardsId,extraRewardsId);
        queryWrapper.eq(EcologyHatchExtraRewardsConfig::getEcologyHatchId,ecologyHatchId);
        return list(queryWrapper);
    }


    public List<EcologyHatchExtraRewardsConfig> findListByExtraRewardsId(Long extraRewardsId) {
        LambdaQueryWrapper<EcologyHatchExtraRewardsConfig> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(EcologyHatchExtraRewardsConfig::getExtraRewardsId,extraRewardsId);

        return baseMapper.selectList(queryWrapper);
    }

    public List<EcologyHatchExtraRewardsConfig> listByMethodId(Long extraRewardsId,Long methodId) {
        LambdaQueryWrapper<EcologyHatchExtraRewardsConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EcologyHatchExtraRewardsConfig::getExtraRewardsId,extraRewardsId);
        queryWrapper.eq(EcologyHatchExtraRewardsConfig::getMethodId,methodId);
        return list(queryWrapper);
    }
}
